package cn.zlb.frame.application.dto.product;

import cn.zlb.frame.common.vo.BaseVO;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.math.BigDecimal;

/**
 * @author yangjie.deng@resico.cn
 * @date 2023-11-09 11:27:37
 * @describe class responsibility
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class ProductDTO extends BaseVO {
    /**
     *  产品编号
     */
    private String productNo;
    /**
     *  产品名称
     */
    private String productName;
    /**
     *  产品描述
     */
    private String productDesc;
    /**
     *  产品价格
     */
    private BigDecimal price;
    /**
     *  库存
     */
    private Integer inventory;
    /**
     *  产品类型
     *  1- 日用品  2-电子产品  3- 穿搭
     */
    private Integer productType;

    public void hasInventory(Integer inventory) {
        final int overage = Math.subtractExact(this.getInventory(), inventory);
        if (overage < 0) {
            throw new RuntimeException("库存不足,无法完成支付");
        }
    }
}
